package com.timmy.bluetooth.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.timmy.bluetooth.R;
import com.timmy.bluetooth.scan.DeviceInfo;

import java.util.List;


/**
 * 蓝牙扫描的 adapter
 */

public class MyAdapter extends BaseAdapter {

    private List<DeviceInfo> mDevices;
    private Context mContext;

    public MyAdapter(Context context, List<DeviceInfo> devices) {
        mDevices = devices;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mDevices.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {

            convertView = View.inflate(mContext, R.layout.item, null);
        }

        TextView tv = (TextView) convertView.findViewById(R.id.item_tv);

        String name = mDevices.get(position).getName();

        tv.setText(name);

        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public String getId(String addr) {
        return (addr.subSequence(9, 11) + addr.substring(12, 14) + addr.substring(15, 17)).toString();
    }
}
